#include "fig_boss_attackmove_circle.h"
#include "fig_boss_attackmove_manager.h"
#include "fig_enemy_boss.h"

#include "math/math_core.h"

FIGBossAttackMoveCircle::FIGBossAttackMoveCircle(FIGBossAttackMoveManager* pManager) :
															FIGBossAttackMove(pManager),
															m_State(STATE_GOTO_CENTER),
															m_CirclingCount(0)
{
	m_CircleCounter.SetLimit(2.0f);
}




void		FIGBossAttackMoveCircle::Tick(float dt)
{
	FIGEnemyBoss* pBoss = m_pManager->GetBoss();	
	if(!pBoss)
		return;

	FIGBossAttackMove::Tick(dt);

	if(m_Delay > 0)
		return;

	

	switch(m_State)
	{
		case STATE_GOTO_CENTER:
		{
			const float Diff = 0.5f - pBoss->m_Pos.x;
			
			if(Diff >= -0.025f && Diff <= 0.025f)
			{
				m_State = STATE_CIRCLE;
				m_Acceleration = 1.0f;
			}
			else if (Diff > 0)
				pBoss->m_Pos.x += m_Acceleration * dt;
			else
				pBoss->m_Pos.x -= m_Acceleration * dt;

			if(m_Acceleration > 0.3f)
				m_Acceleration -= dt;
		}
		break;

		case STATE_CIRCLE:
			{
				m_CircleCounter.Tick(dt);
				if(m_CircleCounter.IsReady())
				{
					m_CircleCounter.Reset();
					m_CirclingCount++;

					if(m_CirclingCount == 2)
					{
						m_pManager->End();
						return;
					}
				}

				const float Radius = 0.25f;
				pBoss->m_Pos.x += (cosf(m_CircleCounter.GetProgress() * MATH_2PI )  * Radius *  dt ); 
				pBoss->m_Pos.y += (sinf(m_CircleCounter.GetProgress() * MATH_2PI)  * Radius *  dt );  
				
				if(pBoss->m_Pos.y < pBoss->m_Radius)
					pBoss->m_Pos.y = pBoss->m_Radius;
			}
		break;
		default:
			break;
	}
	
}
			          

void		FIGBossAttackMoveCircle::Start(float Delay)
{
	FIGBossAttackMove::Start(Delay);
	m_Acceleration = 1.0f;
	m_State = STATE_GOTO_CENTER;
	m_CirclingCount = 0;
}